package com.ruoyi.tasks.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.tasks.dto.BuildingTasksDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.tasks.domain.BuildingTasks;
import com.ruoyi.tasks.service.IBuildingTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 楼栋核酸任务CRUDController
 *
 * @author ruoyi
 * @date 2022-10-05
 */
@RestController
@RequestMapping("/building")
public class BuildingTasksController extends BaseController
{
    @Autowired
    private IBuildingTasksService buildingTasksService;

    /**
     * 查询楼栋核酸任务CRUD列表
     */
    @RequiresPermissions("tasks:building:list")
    @GetMapping("/list")
    public TableDataInfo list(BuildingTasks buildingTasks)
    {
        startPage();
        List<BuildingTasks> list = buildingTasksService.selectBuildingTasksList(buildingTasks);
        return getDataTable(list);
    }

    /**
     * 导出楼栋核酸任务CRUD列表
     */
    @RequiresPermissions("tasks:building:export")
    @Log(title = "楼栋核酸任务CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuildingTasks buildingTasks)
    {
        List<BuildingTasks> list = buildingTasksService.selectBuildingTasksList(buildingTasks);
        ExcelUtil<BuildingTasks> util = new ExcelUtil<BuildingTasks>(BuildingTasks.class);
        util.exportExcel(response, list, "楼栋核酸任务CRUD数据");
    }

    /**
     * 获取楼栋核酸任务CRUD详细信息
     */
    @RequiresPermissions("tasks:building:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(buildingTasksService.selectBuildingTasksById(id));
    }

    /**
     * 新增楼栋核酸任务CRUD
     */
    @RequiresPermissions("tasks:building:add")
    @Log(title = "楼栋核酸任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuildingTasksDto dto)
    {
        return toAjax(buildingTasksService.insertBuildingTasks(dto));
    }

    /**
     * 修改楼栋核酸任务CRUD
     */
    @RequiresPermissions("tasks:building:edit")
    @Log(title = "楼栋核酸任务CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuildingTasks buildingTasks)
    {
        return toAjax(buildingTasksService.updateBuildingTasks(buildingTasks));
    }

    /**
     * 删除楼栋核酸任务CRUD
     */
    @RequiresPermissions("tasks:building:remove")
    @Log(title = "楼栋核酸任务CRUD", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingTasksService.deleteBuildingTasksByIds(ids));
    }
}
